<template>
	<view class="index">
		<view class="top">
			<!-- <view class="news">
				<image src="@/static/index/laba.png" mode=""></image>
			</view> -->
			<view class="logo">
				<image src="@/static/index/logo.png" mode="widthFix"></image>
			</view>
			<view class="search">
				<image src="@/static/index/ss.png" mode="" @click="search()"></image>
				<input confirm-type="search" @confirm="search" placeholder="搜索商品" placeholder-style="color:#fff"
					v-model="searchinput" />
			</view>
		</view>
		<!-- 轮播图 -->
		<view class="swiper">
			<swiper :indicator-dots="true" circular="true" indicator-color="#fff" indicator-active-color="grey"
				:autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item,index) in banner" :key="index">
					<view class="swiper-item" @click="geturl(item.dizhi)">
						<image :src="getimg(item.url)" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 导航栏 -->
		<view class="nav">
			<view class="nav-tab" @click="toPage('/pages/classlist/index')">
				<image src="../../static/index/tab1.png" mode="widthFix"></image>
				<text>商品分类</text>
			</view>
			<view class="nav-tab" @click="toPage('/pages/order/index?id=0')">
				<image src="../../static/index/tab2.png" mode="widthFix"></image>
				<text>我的订单</text>
			</view>
			<view class="nav-tab" @click="toTarPage('/pages/cart/index')">
				<image src="../../static/index/tab3.png" mode="widthFix"></image>
				<text>购物车</text>
			</view>
			<view class="nav-tab" @click="toPage('/pages/charge/index')">
				<image src="../../static/index/tab4.png" mode="widthFix"></image>
				<text>购买年会员</text>
			</view>
			<view class="nav-tab" @click="toTarPage('/pages/user/index')">
				<image src="../../static/index/tab5.png" mode="widthFix"></image>
				<text>会员中心</text>
			</view>
		</view>
		<!-- 专区 -->
		<view class="hot">
			<view class="title">
				<text class="name">体验专区</text>
				<!-- <text class="more">查看更多></text> -->
			</view>
			<view class="goods">
				<view class="goodsitem" v-for="(item,index) in ti" :key='item.id'
					@click="toPage('/pages/goodsdetail/index?id='+item.id)">
					<view class="goodsimg">
						<image :src="getimg(item.logo_url)" mode="widthFix"></image>
					</view>
					<text class="name">{{item.name}}</text>
					<text class="price">体验价：￥<text class="pricenum">{{Number(item.price)}}</text></text>
				</view>

			</view>
		</view>
		<view class="hot">
			<view class="title">
				<text class="name">热门推荐</text>
				<!-- <text class="more">查看更多></text> -->
			</view>
			<view class="goods">
				<view class="goodsitem" v-for="(item,index) in goods" :key='item.id'
					@click="toPage('/pages/goodsdetail/index?id='+item.id)">
					<view class="goodsimg">
						<image :src="getimg(item.logo_url)" mode="widthFix"></image>
					</view>
					<text class="name">{{item.name}}</text>
					<text class="price">零售价：￥<text class="pricenum">{{Number(item.price)}}</text></text>
					<text class="vipprice">会员价：￥{{Number(item.vip_price)}}</text>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		IndexGoods
	} from '../../api/api.js'
	export default {
		data() {
			return {
				banner: [],
				goods: [],
				ti: [],
				searchinput: ''
			}
		},
		onLoad() {
			this.IndexGoods()
			console.log(this.websiteUrl)
		},
		onShow() {
			this.searchinput = ''
		},
		methods: {
			geturl(url) {
				// #ifdef H5
				window.location.href = url;
				// #endif
				// #ifdef APP-PLUS
				plus.runtime.openURL(url) //不需要拼接
				// #endif

			},
			search() {
				uni.navigateTo({
					url: '/pages/Goods/index?search=' + this.searchinput
				})
			},
			IndexGoods() {
				IndexGoods().then(res => {
					console.log(res)
					this.banner = res.list.banner
					this.goods = res.list.bao
					this.ti = res.list.ti
				})
			},
			toPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			toTarPage(url) {
				uni.switchTab({
					url: url
				})
			},
			getimg(url) {
				return this.websiteUrl + url
			}
		}
	}
</script>

<style lang="scss">
	.index {
		background: #F7F7F7;
	}

	.top {
		background: $uni-bg-color;
		padding-bottom: 100px;

		.news {
			text-align: right;
			padding-right: 5%;
			position: fixed;
			top: 8px;
			z-index: 99999;
			right: 2%;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.logo {
			display: flex; 
			justify-content: center;
			padding-bottom: 15px;
			padding-top: 10px;

			image {
				width: 60%;
				height: 4rem;
			}
		}

		.search {
			position: relative;
			width: 90%;
			background: #ffffff4d;
			border-radius: 20px;
			margin: 40rpx auto;

			image {
				width: 20px;
				height: 20px;
				position: absolute;
				left: 10%;
				top: 12px;
			}

			input {
				width: 80%;
				margin-left: 20%;
				line-height: 57px;
				height: 41px;
				color: #fff;
			}


		}

	}
	uni-swiper{
		height: 160px;
	}
	.swiper {
		width: 96%;
		margin: 0 auto;
		margin-top: -80px;
		// height: 8rem;
		border-radius: 10px;

		.swiper-item {
			image {
				width: 90%;
				height: 160px;
				margin-left: 5%;
				border-radius: 10px;
			}
		}
	}

	.nav {
		display: flex;
		justify-content: space-around;
		width: 90%;
		margin: 0 auto;
		margin-top: 50rpx;

		.nav-tab {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 45px;
				height: 45px;
			}

			text {
				font-size: 12px;
				color: #666;
			}
		}
	}

	.hot {
		margin-top: 60rpx;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 90%;
			margin: 0 auto;
			border-left: 4px solid #1D3F2B;
			padding-left: 2%;
			background: #F7F7F7;

			.name {
				color: #1D3F2B;
				font-size: 30rpx;
				font-weight: bold;
			}

			.more {
				font-size: 12px;
				color: #999999;
			}
		}

		.goods {
			display: table;
			width: 100%;
			background: #F7F7F7;

			.goodsitem {
				display: flex;
				flex-direction: column;
				width: 45%;
				float: left;
				margin: 20rpx 2.5%;
				background: #fff;

				.goodsimg {
					width: 100%;

					image {
						width: 100%;
						border-radius: 8px;
					}
				}


				text {
					margin: 10rpx 0;
				}

				.name {
					font-size: 15px;
					width: 92%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					padding: 0 4%;
				}

				.price {
					color: #C79E76;
					font-size: 14px;
					padding-left: 5px;

					.pricenum {
						font-size: 18px;
					}
				}

				.vipprice {
					font-size: 14px;
					padding-left: 5px;
				}
			}
		}
	}
</style>
